package com.youku.expression.ast;

import java.util.List;

import com.youku.expression.environment.Environment;

/**
 * 参数列表
 * 
 * @author loda
 *
 */
public class ArgumentAst extends Ast {

	public ArgumentAst() {
		super();
	}

	public ArgumentAst(Ast... asts) {
		super(asts);
	}

	public ArgumentAst(List<Ast> asts) {
		super(asts);
	}

	public List<Ast> arguments() {
		return children();
	}

	@Override
	public String toString() {
		StringBuilder builder = new StringBuilder();

		for (Ast ast : arguments()) {
			builder.append(ast).append(",");
		}

		if (builder.toString().endsWith(",")) {
			builder.deleteCharAt(builder.length() - 1);
		}

		return builder.toString();
	}

	@Override
	public Object eval(Environment environment) {
		Object[] args=new Object[arguments().size()];
		for(int i=0;i<args.length;i++){
			args[i]=arguments().get(i).eval(environment);
		}
		
		return args;
	}

}
